using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Deployment.CustomTasks;

namespace WizardControls
{
	public interface IWizardScreenControl
	{
		void AddUserControl(IUserControl controlElement);
		event EventHandler Cancel;
	}

	public partial class WizardScreenControl : Form, IWizardScreenControl
	{
		public WizardScreenControl()
		{
			InitializeComponent();
			CancelButton = button_cancel;
			Location = new Point((Screen.PrimaryScreen.WorkingArea.Width - Size.Width)/2,
			                     (Screen.PrimaryScreen.WorkingArea.Height - Size.Height)/2);
		}

		private List<IUserControl> controlElements = new List<IUserControl>();

		public string WizardTitle
		{
			set
			{
				this.label_wizardTitle.Text = value;
			}
		}

		public string Title
		{
			set
			{
				this.groupBox_main.Text = value;
			}
		}


		public void AddUserControl(IUserControl controlElement)
		{
			int x, y;
			x = 10;
			if (controlElements.Count == 0)
				y = 20;
			else
			{
				Control previous = controlElements[controlElements.Count - 1].GetControl();
				y = previous.Location.Y + previous.Size.Height + 1;
			}

			Control control = controlElement.GetControl();
			control.Location = new Point(x, y);
			control.BringToFront();
			this.groupBox_main.Controls.Add(control);
//			controlElements.Add(controlElement);
//			Controls.Add(control);
		}

		public event EventHandler Cancel;

		private void button_cancel_Click(object sender, EventArgs e)
		{
			if (null != Cancel)
				Cancel(this, EventArgs.Empty);
			Close();
		}

		private void button_next_Click(object sender, EventArgs e)
		{
			Close();
		}
	}
}